// $Id: CustomAttributeEditor.cs 64 2008-05-06 18:29:47Z nvivo $

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;

namespace DBLGen.UI.Design
{
	public class CustomSqlEditor : UITypeEditor
	{
		public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			CustomAttributesQuery caq = value as CustomAttributesQuery;

			if (caq != null)
			{
				using (CustomSqlEditorForm frm = new CustomSqlEditorForm(caq))
				{
					if (frm.ShowDialog() == DialogResult.OK)
					{
						return frm.CustomAttributesQuery;
					}
				}
			}

			return value;
		}
	}

	public class CustomAttributeEditor : UITypeEditor
	{
		public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			CustomAttributes ca = value as CustomAttributes;

			if (ca != null)
			{
				using (CustomAttributesEditorForm frm = new CustomAttributesEditorForm(ca))
				{
					if (frm.ShowDialog() == DialogResult.OK)
						return frm.CustomAttributes;
				}
			}

			return value;
		}
	}
}
